<?

class File extends AbstractFile
{

    function File($name) {
        parent::AbstractFile($name);
        $this->size = filesize($name);
        $this->modified = filectime($name);
        $this->fname = basename($this->name);
    }

    function delete() {
        unlink($this->name);
    }

    function copyTo($dest) {
        if (is_dir($dest)) {
            return copy($this->name,$dest);
        }
    }

    function moveTo($dest) {
        if ($this->copyTo($dest)) {
            if ($this->delete()) {
                $this->name = $dest.(substr($dest,-1) == '/' ? '' : '/').$basename($this->name);
            } else {
                return false;
            }
        } else {
            return false;
        }
        return true;
    }

    function getSize() {
        return $this->size;
    }

    function getSizeF() {
        $size = $this->size;
        if ($size < 1024) {
            return $size.' b';
        } elseif ($size < 1024 * 1024) {
            return sprintf("%01.2f kb",$size/1024);
        } elseif ($size < 1024 * 1024 * 1024) {
            return sprintf("%01.2f Mb",$size/pow(1024,2));
        } else {
            return sprintf("%01.2f Gb",$size/pow(1024,3));
        }
    }

    function getExt() {
        $res = preg_match("/^((?!\/)[a-zA-Z0-9\._-]+)\./U",strrev($this->name),$regs);
        if (isset($regs[1])) {
            return strtolower(strrev($regs[1]));
        } else {
            return '';
        }
    }

    function getInfo() {
        $ext = $this->getExt();
        $FILETYPES = Config::getValue('filetypes','FILETYPES');

        $res = '';
        foreach ($FILETYPES as $filetype) {
            if (in_array($ext,$filetype['extensions'])) {
                $res = $filetype;
            }
        }
        if ($res == '') {
            $res = $FILETYPES['default'];
        }
        return $res;
    }
}

?>